// 基本信息
<template>
  <Form :model="formItem" :label-width="110">
    <FormItem label="商户名称">
      <Input v-model="formItem.name" placeholder="商户名称"></Input>
    </FormItem>
    <FormItem label="联系电话">
      <Input v-model="formItem.tel" placeholder="联系电话"></Input>
    </FormItem>
    <FormItem label="联系地址">
      <Input v-model="formItem.address" placeholder="联系地址"></Input>
    </FormItem>
    <FormItem label="地址经纬度">
      <Input v-model="formItem.coordinate" placeholder="地址经纬度"></Input>
    </FormItem>
    <FormItem label="起送金额">
      <Input v-model="formItem.send_price" placeholder="起送金额"></Input>
    </FormItem>
    <FormItem label="配送费">
      <Input v-model="formItem.delivery_fee" placeholder="配送费"></Input>
    </FormItem>
    <FormItem label="商城简介">
      <Input v-model="formItem.remarks" placeholder="商城简介"></Input>
    </FormItem>

    <FormItem label="小程序分享图片">
      <img v-bind:src="formItem.img" alt="">
      <Upload action="http://upload-z2.qiniup.com" :data="updata" :on-success="files" :on-remove="removeFiles" :on-error="error">
        <Button icon="ios-cloud-upload-outline">上传图片</Button>
      </Upload>
    </FormItem>
    <FormItem>
      <Button type="primary" @click.stop="primary">确认</Button>
      <Button type="error" style="margin-left: 8px">取消</Button>
    </FormItem>
  </Form>
</template>

<script type="text/ecmascript-6">
export default {
  data() {
    return {
      formItem: {},
      imgs: "",
      updata: {
        key: Date.parse(new Date()) + ".jpg",
        token: ""
      }
    };
  },
  created() {
     this.getToken();
    this.getShopInfo();
  },
  methods: {
        removeFiles: function() {
      this.getToken();
      this.updata.key = Date.parse(new Date()) + ".jpg";
    },
    getToken: function() {
      let _self = this;
      $.ajax({
       url: BASE_URL+'upload/token',
        type: "get",
        success: function(e) {
          _self.updata.token = e;
        }.bind(this)
      });
    },
    error: function(response, file, fileList) {
      console.log(response, file, fileList);
    },
    files: function(res, file) {
      console.log(file);
      console.log(IMAGE_URL +'/'+ res.key);
      this.formItem.img = IMAGE_URL +'/'+ res.key;
    },
    getShopInfo: function() {
      $.ajax({
        url: BASE_URL + "groupset/groupBusinessInfo",
        type: "get",
        success: function(res) {
          console.log(res);
          this.formItem = res;
        }.bind(this)
      });
    },
    primary: function() {
      console.log(this.formItem);
      $.ajax({
        url: BASE_URL + "groupset/update",
        type: "get",
        data: {
          groupBusinessInfo: JSON.stringify(this.formItem)
        },
        success: function(res) {
          if (res) {
            this.getShopInfo();
          }
        }.bind(this)
      });
    }
  }
};
</script>

<style scoped >
</style>
